Bletchley Python Test

Congratulations. You have been selected for the second round in the Bletchley application process. In this test, we ask you to complete two Python assignments. One asks for your general knowledge of the Python syntax. The other one asks for a bit of knowledge on numpy and vectors. Remember: Using google is okay!. We don't expect you to know everything by heart, we just want to make sure you can solve a problem somehow.

Where to run the code

You can run all code that is required for this assignment on either Microsoft Azure Notebooks or by installing Python and all required libraries yourself from Anaconda.

How to submit this assignment

You can submit your answer to this assignment by emailing the answers to jannes [at] tscociety.io

Assignment 1: Python Syntax

Write a program which will find all numbers divisible by 17 but not a divisible of 5, between 1337 and 2412 inclusively. For example 1343 is divisible by 17 and not by 5 so it should be added. 2040 is divisible by 17 and by five so it should not be added.

Question 1:

How many numbers fit the specifications?

Question 2:

What is the sum of the numbers?

You can complete this assignment without any third party library. Consider using:

  • a list
  • the range function
  • the remainder operator
  • an if statement
  • the list append function

In [ ]:
# Define function

In [ ]:
# Print out number of found answers

In [ ]:
# Print out sum of found numbers

Assignment 2: Numpy and Vectors

Import numpy. Create two vectors containing the numbers 0 to 23 inclusively in order. 0,1,2,3,4... etc.

Question 3:

What is the inner product (dot product) of the two vectors?

Question 4:

Now multiply the two vectors element wise. What is the seventh element of the new vector?

Consider using:

  • numpy's arrange function
  • numpy's dot function
  • numpy's multiply

Remember, indexes start counting at zero.


In [ ]:
# import numpy

In [ ]:
# create vectors

In [ ]:
# Calculate and print dot product

In [ ]:
# Calculate element wise multiplication
# Print the 7th element